package com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.dao;

import com.skytech.tax.customsdatawarehouse.singlewindow.taxhandle.domain.entity.TaxBillPaymentDetails;
import org.joda.time.DateTime;
import org.springframework.jdbc.core.namedparam.BeanPropertySqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * @author Lianhong
 * @since 2022/7/14
 */
@Repository
public class TaxBillPaymentDetailsDao {

    @Resource
    private NamedParameterJdbcTemplate namedParameterJdbcTemplate;

    private String deleteTaxBillPaymentDetailsSql = "DELETE FROM sw_tax_bill_payment_details WHERE taxPayId = ?";

    public void delete(String taxPayId) {
        this.namedParameterJdbcTemplate.getJdbcOperations().update(this.deleteTaxBillPaymentDetailsSql, taxPayId);
    }

    private String saveTaxBillPaymentDetailsSql = "INSERT INTO sw_tax_bill_payment_details (taxPayId, paymentDetails, storageTime) VALUES (:taxPayId, :paymentDetails, :storageTime)";

    public void save(TaxBillPaymentDetails details) {
        details.setStorageTime(DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
        this.namedParameterJdbcTemplate.update(this.saveTaxBillPaymentDetailsSql, new BeanPropertySqlParameterSource(details));
    }
}


